﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JiaBoPrint
{
    public partial class 沙驰商品尺寸打印多 : Form
    {
        private IntPtr Gp_IntPtr;                   //驱动打印句柄
        private libUsbContorl.UsbOperation NewUsb = new libUsbContorl.UsbOperation();
        public 沙驰商品尺寸打印多()
        {
            InitializeComponent();
        }
        private void SendData2USB(byte[] str)
        {
            NewUsb.SendData2USB(str, str.Length);
        }
        private void SendData2USB(string str)
        {
            byte[] by_SendData = System.Text.Encoding.GetEncoding(54936).GetBytes(str);
            SendData2USB(by_SendData);
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)//如果输入的是回车键  
            {
                string dm = textBox1.Text.ToString();
                string sqldm = @"exec [zdy_getPrint2] '{0}'";
                sqldm = string.Format(sqldm, dm);
                DataTable dtdm = DBHelper2.ExecuteDataTable(sqldm);
                if (dtdm.Rows.Count > 0)
                {
                    NewUsb.FindUSBPrinter();
                    for (int k = 0; k < NewUsb.USBPortCount; k++)
                    {
                        if (NewUsb.LinkUSB(k))
                        {
                            SendData2USB("SIZE 60 mm,80 mm\r\n");//设置标签大小，单位mm.具体参数请用尺子量一下
                            SendData2USB("GAP 2 mm,0 mm\r\n");//设置两个标签之间的间隙，单位mm.具体参数请用尺子量一下
                            SendData2USB("CLS\r\n");//清空缓冲区
                            SendData2USB("DENSITY 7\r\n");//打印浓度
                            SendData2USB("REFERENCE 0,0\r\n");

                            SendData2USB("TEXT 10,10,\"TSS24.BF2\",0,1,1,\"款号:\"\r\n");
                            SendData2USB("TEXT 120,10,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["kh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,50,\"TSS24.BF2\",0,1,1,\"品名:\"\r\n");
                            SendData2USB("TEXT 120,50,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["pm"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,90,\"TSS24.BF2\",0,1,1,\"工厂:\"\r\n");
                            SendData2USB("TEXT 120,90,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["gc"].ToString() + "\"\r\n");


                            SendData2USB("TEXT 150,130,\"TSS24.BF2\",0,1,1,\"上会样\"\r\n");
                            SendData2USB("TEXT 300,130,\"TSS24.BF2\",0,1,1,\"大货尺寸\"\r\n");

                            SendData2USB("TEXT 10,170,\"TSS24.BF2\",0,1,1,\"版型:\"\r\n");
                            SendData2USB("TEXT 130,170,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["bx_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,170,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["bx_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,210,\"TSS24.BF2\",0,1,1,\"前/后长:\"\r\n");
                            SendData2USB("TEXT 130,210,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["qianhouchang_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,210,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["qianhouchang_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,250,\"TSS24.BF2\",0,1,1,\"肩宽:\"\r\n");
                            SendData2USB("TEXT 130,250,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["jiankuan_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,250,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["jiankuan_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,290,\"TSS24.BF2\",0,1,1,\"胸围:\"\r\n");
                            SendData2USB("TEXT 130,290,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["xiongwei_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,290,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["xiongwei_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,330,\"TSS24.BF2\",0,1,1,\"腰围:\"\r\n");
                            SendData2USB("TEXT 130,330,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["yaowei_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,330,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["yaowei_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,370,\"TSS24.BF2\",0,1,1,\"摆围:\"\r\n");
                            SendData2USB("TEXT 130,370,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["baiwei_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,370,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["baiwei_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,410,\"TSS24.BF2\",0,1,1,\"袖长:\"\r\n");
                            SendData2USB("TEXT 130,410,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["xiuchang_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,410,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["xiuchang_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,450,\"TSS24.BF2\",0,1,1,\"袖肥:\"\r\n");
                            SendData2USB("TEXT 130,450,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["xiufei_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,450,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["xiufei_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,490,\"TSS24.BF2\",0,1,1,\"夹圈:\"\r\n");
                            SendData2USB("TEXT 130,490,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["jiaquan_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,490,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["jiaquan_dh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 10,530,\"TSS24.BF2\",0,1,1,\"袖口:\"\r\n");
                            SendData2USB("TEXT 130,530,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["xiukou_sh"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 320,530,\"TSS24.BF2\",0,1,1,\"" + dtdm.Rows[0]["xiukou_dh"].ToString() + "\"\r\n");

                            SendData2USB("PRINT 1\r\n");
                            NewUsb.CloseUSBPort();

                            textBox1.Text = "";
                        }
                        else
                        {
                            MessageBox.Show("请确定是否连接上打印机");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("款号不正确");
                }
            }
        }
    }
}
